package com.ghd.dataviz.controller;

import com.ghd.dataviz.core.param.DatavizResponse;
import com.ghd.dataviz.core.utils.JsonUtil;
import com.ghd.dataviz.param.GetKpiParam;
import com.ghd.dataviz.param.KpiDatas;
import com.ghd.dataviz.service.IRealtimeDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ：ghd
 * @date ：Created in 2020-03-10 22:23
 * @description：实时数据管理/查询相关接口
 * @modified By：
 * @version: 1.0$
 */
@RestController
@Api(tags = "实时数据管理/查询相关接口")
@RequestMapping("kpi")
public class KpiController {
    private final IRealtimeDataService realtimeDataService;

    public KpiController(IRealtimeDataService realtimeDataService) {
        this.realtimeDataService = realtimeDataService;
    }


    @PostMapping("get-datas")
    @ApiOperation("根据kpi名称查询实时数据")
    public DatavizResponse<Map<String, List<List<String>>>> getKpiDatas(@RequestBody GetKpiParam param) {
        KpiDatas datas = realtimeDataService.getKpiDatasByKpis(param.getKpis());
        System.out.println(JsonUtil.objectToJson(SecurityContextHolder.getContext().getAuthentication()));
        return DatavizResponse.success(datas.getData());
    }

    @GetMapping("get-all-datas")
    @ApiOperation("查询全部实时数据")
    public DatavizResponse<Map<String, List<List<String>>>> getAllKpiDatas() {
        KpiDatas datas = realtimeDataService.getAllKpiDatas();
        return DatavizResponse.success(datas.getData());
    }


}
